package com.houtai.authority;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Component
public class InterceptorConfiguration extends WebMvcConfigurerAdapter {



    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
    @Override public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        AuthorityAnnotationInterceptor authorityAnnotationInterceptor = new AuthorityAnnotationInterceptor();
        authorityAnnotationInterceptor.setRedisTemplate(redisTemplate);
        InterceptorRegistration ir = registry.addInterceptor(authorityAnnotationInterceptor);
        // 配置拦截的路径
        ir.addPathPatterns("/api/**");

        // 配置不拦截的路径
        ir.excludePathPatterns("/**.html");
        ir.excludePathPatterns("/webjars/**");
    }
}


